package com.itheima.server.controller;

import com.itheima.server.service.UserService;
import com.itheima.tanhua.dubbo.api.UserApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    @DubboReference
    private UserApi userApi;


    /**
     * 发送短信验证码
     * @param map
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map){

        String phone = (String) map.get("phone");

        //发送短信验证码
        userService.sendMsg(phone);

        return ResponseEntity.ok("发送验证码成功");
    }

    /**
     * 登录验证
     * @param map
     * @return
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map){
        String phone = (String) map.get("phone");

        String code = (String) map.get("verificationCode");


        Map result = userService.loginVerification(phone,code);

        return ResponseEntity.ok(result);

    }
}
